/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.MOS.javacc.utils;

import java.io.FileFilter;

/**
 *
 * @author Leonardo Baptista (cbs) - http://cbs.net.br
 */
public class File {

    public static String[] getAllFilesWithExtensions(String p_path,final String[] p_extensions){
        String[] retorno = null;

        FileFilter filter = new FileFilter() {

            public boolean accept(java.io.File arg0) {
                String nome = arg0.getAbsolutePath();
                String extensao = nome.substring(nome.length()-3, nome.length());
                for(int i=0;i<p_extensions.length;i++){
                    if (extensao.equals(p_extensions[i]) ){
                        return true;
                    }
                }
                return false;
            }
        };

        java.io.File file = new java.io.File(p_path);
        java.io.File[] files = file.listFiles(filter);
        if (files.length < 1)
            return null;
        retorno = new String[files.length];
        for (int fileInList = 0; fileInList < files.length; fileInList++){
            //retorno[fileInList] = files[fileInList].getAbsolutePath();
            retorno[fileInList] = files[fileInList].getName();
        }

        return retorno;
    }

}
